package com.offer;


import com.utils.DataUtils;

import java.util.HashSet;

public class Test48 {

    public int lengthOfLongestSubstring(String s) {
        int max = 0;

        char[] chars = s.toCharArray();

        HashSet<Character> hashSet = new HashSet<>();

        for (int i = 0, j = 0; j < chars.length; ) {
            if (hashSet.contains(chars[j])) {
                hashSet.remove(chars[i]);
                i++;
            } else {
                hashSet.add(chars[j]);
                j++;
            }
            max = Math.max(hashSet.size(), max);
        }

        return max;
    }

    public static void main(String[] args) {
        Test48 test = new Test48();
        System.out.println(test.lengthOfLongestSubstring("abcabcbb"));
    }

}
